package com.hua.server.oauth.strategy.impl;

import com.hua.server.oauth.strategy.AuthorizationServerConfigurerStrategy;
import com.hua.server.oauth.strategy.TypeAuthorizationServerHandler;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.stereotype.Component;

@Component
@TypeAuthorizationServerHandler("memory")
public class InMemoryAuthorizationServerConfigStrategy implements AuthorizationServerConfigurerStrategy {
    @Override
    public void configure(ClientDetailsServiceConfigurer clients, PasswordEncoder passwordEncoder) throws Exception {
        clients
                .inMemory()
                .withClient("client")
                .secret(passwordEncoder.encode("secret"))
                .scopes("app")
                .accessTokenValiditySeconds(600)
                .authorizedGrantTypes("authorization_code")
                .redirectUris("https://www.baidu.com")
                .and()
                .withClient("clientP")
                .scopes("app")
                .secret(passwordEncoder.encode("secret"))
                .authorizedGrantTypes("password")
                .accessTokenValiditySeconds(600);
    }

    @Override
    public TokenStore configure(AuthorizationServerEndpointsConfigurer endpoints) {
        return null;
    }
}
